// 校验当前上传类型
export const checkFileType = (
  file: string,
  accpet: string,
  isReturnType: Boolean = false,
): boolean | string => {
  const index = file.lastIndexOf('.');
  const fileAccpet = index > -1 ? file.substring(file.lastIndexOf('.')) : '';
  if (isReturnType) {
    return fileAccpet;
  }

  const fileTypeList: string[] = accpet.split(',');

  const newTypes = fileTypeList.join('|');
  const reg = new RegExp('(' + newTypes + ')$', 'i');

  return reg.test(fileAccpet);
};

// 校验当前文件大小 maxSize单位 MB
export const checkFileSize = (fileSize: number, maxSize: number): boolean => {
  const size: number = fileSize / 1024 / 1024;
  return size < maxSize;
};
